package com.struts.action;

import java.util.Map;

import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.apache.struts2.ServletActionContext;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.inject.Context;
import com.opensymphony.xwork2.util.ValueStack;

public class MapContextAction extends ActionSupport{
	
	
	
	/**
	 * 测试01：把key:value放入到map栈中的reuqest域中
	 * @return
	 */
	public String putObjectToMapStack_Request() {
		HttpServletRequest request = ServletActionContext.getRequest() ;
		request.setAttribute("request", "aaaaa") ;
		ValueStack valueStack = ActionContext.getContext().getValueStack() ;
		return SUCCESS ;
	}
	
	/**
	 * 测试02：把对象放入到map栈中的application域中
	 * @return
	 */
	public String putObjectToMapStack_Application() {
		ServletContext servletContext = ServletActionContext.getServletContext() ;
		servletContext.setAttribute("application", "aaaaa") ;
		ValueStack valueStack = ActionContext.getContext().getValueStack() ;
		return SUCCESS ;
	}
	
	/**
	 * 测试03：把key:value直接放入到map栈中的第一种方式
	 * @return
	 */
	public String putObjectToMapStack_1() {
		ActionContext context = ActionContext.getContext() ;
		context.put("String", "aaaaa") ;
		context.put("String1", "aaaaa") ;
		context.put("String2", "aaaaa") ;
		context.put("String3", "aaaaa") ;
		System.out.println(context.get("String"));
		System.out.println(context.get("String1"));
		System.out.println(context.get("String2"));
		System.out.println(context.get("String3"));
		return SUCCESS ;
	}
	

}
